package com.ericsson.smart;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ericsson.smart.constant.HierarchyEnum;
import com.ericsson.smart.dto.GeographyDimension;
import com.ericsson.smart.factory.UtilityDimnDAOFactory;
@Component
public class UtilityDimnMetaDataLoader {
	// String dimensionName = "Geography";
	String dimensionName = "DIM_GEOGRAPHY";

	GeographyDimension geographyDimension = new GeographyDimension();

	//UtilityDimnDAOFactory dimensionDAOFactory = new UtilityDimnDAOFactory();

	ArrayList<String> dimensionListName = new ArrayList<String>();
	@Autowired
	UtilityDimensionDAO dimensionDAO;
	@Autowired
	UtilityCommon utilCommon;
	//= dimensionDAOFactory.getDimensionDAO(dimensionName);

	public UtilityDimensionDAO getDimensionDAO() {
		return dimensionDAO;
	}

	public void setDimensionDAO(UtilityDimensionDAO dimensionDAO) {
		this.dimensionDAO = dimensionDAO;
	}

	public List<String> creatingDimensionList() {
		dimensionListName.add("DIM_GEOGRAPHY");
		dimensionListName.add("DIM_TIME");
		dimensionListName.add("DIM_SUBSTATION");
	
		return dimensionListName;
	}

	@SuppressWarnings("unchecked")
	public <T> HashMap<String, ArrayList<T>> loadDimnMetaData(List<String> dimensionListNames) {
		HashMap<String, ArrayList<T>> dimensionMap = new HashMap<String, ArrayList<T>>();
		ArrayList<T> listDimHierarchy;
		HierarchyEnum hierEnum;
		for (String listNames : dimensionListNames) {
			hierEnum = utilCommon.getHierachyForDimension(listNames.trim().toUpperCase());
			listDimHierarchy = (ArrayList<T>) dimensionDAO.getHierarchy(hierEnum.getTable(),
					hierEnum.getId());
			dimensionMap.put(listNames.trim().toUpperCase(), listDimHierarchy);

			// // ??? - Can these conditions be removed and made some generic construct ???
			// if (listNames.equalsIgnoreCase("DIM_GEOGRAPHY")) {
			// ArrayList<T> listGeoHierarchy = (ArrayList<T>) dimensionDAO.getHierarchy(
			// HierarchyEnum.HIERARCHY_GEOGRAPHY.getTable(),
			// HierarchyEnum.HIERARCHY_GEOGRAPHY.getColumn());
			// dimensionMap.put("DIM_GEOGRAPHY", listGeoHierarchy);
			// } else if (listNames.equalsIgnoreCase("DIM_TIME")) {
			// ArrayList<T> listTimeHierarchy = (ArrayList<T>) dimensionDAO.getHierarchy(
			// HierarchyEnum.HIERARCHY_TIME.getTable(),
			// HierarchyEnum.HIERARCHY_TIME.getColumn());
			// dimensionMap.put("DIM_TIME", listTimeHierarchy);
			// } else if (listNames.equalsIgnoreCase("DIM_SUBSTATION")) {
			// ArrayList<T> listSubstationHierarchy = (ArrayList<T>) dimensionDAO.getHierarchy(
			// HierarchyEnum.HIERARCHY_SUBSTATION.getTable(),
			// HierarchyEnum.HIERARCHY_SUBSTATION.getColumn());
			// dimensionMap.put("DIM_SUBSTATION", listSubstationHierarchy);
			// }
		}
		return dimensionMap;
	}

	// @SuppressWarnings("unchecked")
	/*
	 * public <T> HashMap<String, ArrayList<String>> loadDimnMetaData(List<String> dimentionNames) {
	 * UtilityDimensionDAO dimensionDAO=dimensionDAOFactory.getDimensionDAO(dimensionName);
	 * //System.out.println(dimensionDAO.getHierarchy(HierarchyEnum.HIERARCHY_GEO.getTable(),
	 * HierarchyEnum.HIERARCHY_GEO.getColumn())); for(String s: dimentionNames) {
	 * if(s.equalsIgnoreCase("DIM_GEO")) {
	 * @SuppressWarnings("unchecked") ArrayList<T> listGeoHierarchy=(ArrayList<T>)
	 * dimensionDAO.getHierarchy(HierarchyEnum.HIERARCHY_GEO.getTable(),
	 * HierarchyEnum.HIERARCHY_GEO.getColumn()); dimensionMap.put("geoDimensionHierarchy",
	 * (ArrayList<String>) listGeoHierarchy) ; } if(s.equalsIgnoreCase("DIM_GEO")) {
	 * @SuppressWarnings("unchecked") ArrayList<T> listTimeHierarchy=(ArrayList<T>)
	 * dimensionDAO.getHierarchy(HierarchyEnum.HIERARCHY_TIME.getTable(),
	 * HierarchyEnum.HIERARCHY_TIME.getColumn()); dimensionMap.put("TimeHierarchy",
	 * (ArrayList<String>) listTimeHierarchy) ; } } return dimensionMap; }
	 */

}
